//
//  OrderDetailsTableViewCell.m
//  SeaMelonSeeds_Counselor
//
//  Created by 尤振宇 on 2017/7/28.
//  Copyright © 2017年 杨笑. All rights reserved.
//

#import "OrderDetailsTableViewCell.h"
#import "ClassificationViewController.h"
#import "ClassificationCell.h"
#import "GaugeApi.h"

@implementation OrderDetailsTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;

    [self.detailsBtn borderWidthAndColor:k65ACFE];
    [self.detailsBtn roundedCorners_10PX];

    [self.tableBtn roundedCorners_5PX];
    [self.otherBtn roundedCorners_5PX];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (IBAction)buutonAction:(id)sender {
    if (sender == self.detailsBtn) {
        self.detailsAction(self);
    }else if (sender == self.tableBtn){
        self.tableAction(self);
    }else if (sender == self.otherBtn){
        self.otherAction(self);
    }
}

//-(void)setOrder:(Order *)order
//{
//    _order = order;
//    
//    [self.headPortrait sd_setImageWithURL:[NSURL URLWithString:order.user_avatar] placeholderImage:[UIImage imageNamed:@"My_TheDefaultAvatar"]];
//    self.title.text = [NSString stringWithFormat:@"%@  %d岁  %@",order.nickname,order.age,order.sex?@"女":@"男"];
//    self.line.hidden = self.order.spread?NO:YES;
//    self.describe.object = order;
//    
//    self.bookingNo.text = [NSString stringWithFormat:@"预约号: %@",order.out_trade_no];
//    self.pay.text = [NSString stringWithFormat:@"%@ %.0f",order.is_pay?@"已支付":@"未支付",order.total_fee];
//    if (order.allow_check) {
//        self.applyForBtn.enabled = YES;
//        [self.applyForBtn setTitle:@"查看咨询履历" forState:(UIControlStateNormal)];
//    }else{
//        [self.applyForBtn setTitle:@"申请查看咨询履历" forState:(UIControlStateNormal)];
//        self.applyForBtn.enabled = order.allow_send_check;
//    }
//}

-(void)setOrder:(OrderService *)order
{
    self.depoyabel.object = order;
    self.name.text = [NSString stringWithFormat:@"%@  %d岁  %@",order.nickname,order.age,order.sex?@"女":@"男"];
    
    if (order.status == 0) {
        [self.orderStateBtn setTitle:@"未完成" forState:UIControlStateNormal];
        [self.orderStateBtn setImage:[UIImage imageNamed:@"dingdanweikaishi"] forState:UIControlStateNormal];
        self.time.text = @"订单尚未开始";
        [self.otherBtn setTitle:@"开始" forState:UIControlStateNormal];
        
        self.tableBtn.enabled = YES;
        if (!order.allow_send_gauge) {
            [self.tableBtn setTitle:@"查看诊前量表" forState:UIControlStateNormal];
        }else{
            [self.tableBtn setTitle:@"发送诊前量表" forState:UIControlStateNormal];
        }
    }else if (order.status == 1){
        
        if (order.surplus_minites > 0) {
            [self.otherBtn setTitle:@"继续通话/结束" forState:UIControlStateNormal];
        }else{
            [self.otherBtn setTitle:@"结束" forState:UIControlStateNormal];
        }
        
        [self.orderStateBtn setTitle:@"进行中" forState:UIControlStateNormal];
        [self.orderStateBtn setImage:[UIImage imageNamed:@"dingdanjinxingzhong"] forState:UIControlStateNormal];
        self.time.text = [NSString stringWithFormat:@"起止时间: %@",order.begined_at];

        [self.tableBtn setTitle:@"查看诊前量表" forState:UIControlStateNormal];
        //需求是只有诊前才能发
        //允许发送 说明没发过 所以不能查看
        self.tableBtn.enabled = !order.allow_send_gauge;
    }else if (order.status == 2){
        if (order.allow_create) {
            [self.orderStateBtn setTitle:@"待诊断" forState:UIControlStateNormal];
            [self.orderStateBtn setImage:[UIImage imageNamed:@"dingdanjinxingzhong"] forState:UIControlStateNormal];
            [self.otherBtn setTitle:@"填写诊断记录" forState:UIControlStateNormal];
            self.time.text = [NSString stringWithFormat:@"起止时间: %@ 至 %@",order.begined_at,order.ended_at];
        }else{
            [self.orderStateBtn setTitle:@"已完成" forState:UIControlStateNormal];
            [self.orderStateBtn setImage:[UIImage imageNamed:@"dingdanyiwancheng"] forState:UIControlStateNormal];
            [self.otherBtn setTitle:@"诊断结果" forState:UIControlStateNormal];
            self.time.text = [NSString stringWithFormat:@"起止时间: %@ 至 %@",order.begined_at,order.ended_at];
            
        }
        [self.tableBtn setTitle:@"查看诊前量表" forState:UIControlStateNormal];
        self.tableBtn.enabled = !order.allow_send_gauge;
    }
    
    [self.orderStateBtn layoutImageToLeft:5];
}

@end
